#!/bin/bash -
#=======================================================================
#
#          FILE: clean_trail.sh
#         USAGE: ./clean_trail.sh <dir>
#   DESCRIPTION: Remove trailing white spaces for *.c *.h files
#  REQUIREMENTS: sed
#          BUGS: N/A
#         NOTES: N/A
#        AUTHOR: Ali Ayoub
#         EMAIL: ali@mellanox.com
#       COMPANY: N/A
#       CREATED: 09.17.2010-15:51:07
#      REVISION: 1.0
#=======================================================================


USAGE="Usage: $0 <dir>"
EXAMPLE="Example: $0 ./"
if [ $# != 1 ]; then
        echo $USAGE
        echo $EXAMPLE
        exit 1
fi

dir=$1
rm -rf /tmp/$$ &> /dev/null
mkdir -p /tmp/$$
for f in `find  $dir -type f -iname *.[ch]`; do cp $f /tmp/$$ ; done
find $dir -iname *.[ch] -type f -exec sed -i 's/ *$//' '{}' ';'
for f in `find  $dir -type f -iname *.[ch]`; do diff /tmp/$$/`basename $f` $f &> /dev/null || echo $f fixed; done
echo "done"
rm -rf /tmp/$$ &> /dev/null

